//
//  ChainProgrammingVC.m
//  UILbrary
//
//  Created by mac on 16/7/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ChainProgrammingVC.h"

@implementation ChainProgrammingVC
- (void)viewDidLoad{
    [super viewDidLoad];
    /************************
     教程地址http://www.jianshu.com/p/7242c3a5160d
     
     
     */
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    [button setTitle:@"不带参数的链式编程" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:button];
    
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(button.frame), CGRectGetMaxY(button.frame) + 30,button.frame.size.width, button.frame.size.height)];
    button1.backgroundColor = [UIColor orangeColor];
    [button1 setTitle:@"带参数的链式编程" forState:UIControlStateNormal];
    [self.view addSubview:button1];
    [button1 addTarget:self action:@selector(buton1Click) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark 不带参数的方法
- (void)buttonClick{
    self.play().study();
}

- (ChainProgrammingVC *(^)())play{
    return ^(){
        NSLog(@"play");
        return self;
    };
}

- (ChainProgrammingVC * (^)())study{
    return ^(){
        NSLog(@"study");
        return self;
    };
}

#pragma mark - 带参数的方法
- (void)buton1Click{
//    self.learn(@"ios").costTime(@"一个月");
//    [[self learn](@"ios") costTime](@"一个月");

    [self whoLearn:@"王斌斌"](@"ios").costTime(@"一年");
}
- (ChainProgrammingVC *(^)(NSString *str))learn{
    return ^(NSString *str){
        NSLog(@"我们在研究%@",str);
        return self;
    };
}


- (ChainProgrammingVC *(^)(NSString *str))costTime{
    return ^(NSString *str){
        NSLog(@"花费了我们%@时间",str);
        return self;
    };
}

- (ChainProgrammingVC *(^)(NSString *))whoLearn:(NSString *)who{
    
    __block NSString * blockWho = who;
    return ^(NSString *str){
        NSLog(@"%@学习%@",blockWho,str);
        return self;
    };
}
@end
